package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AOutbound;
import com.ruoyi.lock.service.IAOutboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出库单Controller
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/lock/outbound")
public class AOutboundController extends BaseController
{
    @Autowired
    private IAOutboundService aOutboundService;

    /**
     * 查询出库单列表
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(AOutbound aOutbound)
    {
        startPage();
        List<AOutbound> list = aOutboundService.selectAOutboundList(aOutbound);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AOutbound aOutbound)
    {
        List<AOutbound> list = aOutboundService.selectAOutboundList(aOutbound);
        ExcelUtil<AOutbound> util = new ExcelUtil<AOutbound>(AOutbound.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:query')")
    @GetMapping(value = "/{oId}")
    public AjaxResult getInfo(@PathVariable("oId") Long oId)
    {
        return success(aOutboundService.selectAOutboundByOId(oId));
    }

    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AOutbound aOutbound)
    {
        return toAjax(aOutboundService.insertAOutbound(aOutbound));
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AOutbound aOutbound)
    {
        return toAjax(aOutboundService.updateAOutbound(aOutbound));
    }

    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('lock:outbound:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oIds}")
    public AjaxResult remove(@PathVariable Long[] oIds)
    {
        return toAjax(aOutboundService.deleteAOutboundByOIds(oIds));
    }
}
